package com.demo.server.service;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo.server.entity.Log;
import com.demo.server.entity.dto.LogDto;
import com.demo.server.entity.req.LogSearchReq;
import com.demo.server.mapper.LogMapper;
import com.demo.server.util.Result;
import com.demo.server.util.ResultPage;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


@Service
public class LogService {

	@Autowired
	LogMapper logMapper;
	
	/**
	 * @title 查询日志
	 * @param req
	 * @return ResultPage<Log>
	 */
	public ResultPage<Log> search(LogSearchReq req){
		Page<Object> page = PageHelper.startPage(req.getPage(), req.getSize());
		LogDto dto = new LogDto();
		BeanUtils.copyProperties(req, dto);
		List<Log> logs = logMapper.select(dto);
		return ResultPage.success(logs, page.getTotal());
	}
	
	/**
	 * @title 清空日志
	 * @return Result
	 */
	public Result clear(){
		logMapper.clear();
		return Result.success();
	}
}
